<!DOCTYPE html>
<html>
    <%@page import="modelo.Product"%>
    <%@page import="infraestructura.PersistenceManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/estilos.css" type="text/css" charset="utf-8"/>
        <script src="js/jquery-1.4.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/cesta.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
        <div class="pagina">
            <%@include file= "cabecera.jsp" %>
            <div class="cuerpo">
                
                <div class="productos contenedor">
                    <% if (request.getCookies().length == 1 || request.getCookies().length == 0) { %>
                No hay productos en su cesta.
                <% } else { %>
                    Estos son los productos actualmente en su carro:
                    <% Cookie[] arrayCookies = request.getCookies();
                    boolean allowConfirmation = false;
                        PersistenceManager mang = PersistenceManager.getPersistenceManager(getServletContext().getInitParameter("persistenceMethod"));     %>
                    <form>
                    <% Double total = 0.0;
                    for(Cookie oneCookie:arrayCookies){ 
                        if (oneCookie.getName().equals("JSESSIONID")) continue;
                        allowConfirmation = true;
                        System.out.println(oneCookie.getName());
                        Product producto = mang.getProduct(Integer.parseInt(oneCookie.getName()));
                        
                    %>
                    <div class="producto">
                        <img src="imgs/Productos/<%= oneCookie.getName()%>.jpg">
                        <span class="producto"><%= producto.getName()%> x <%= oneCookie.getValue()%></span>
                        <% total += producto.getPrice()*Double.parseDouble(oneCookie.getValue()); %>
                    </div>
                    <% } %>                    
                    </form>
                    <div class="clear"></div>
                    <div class="subtotal"><%= total %></div>
                    <% if(allowConfirmation) {%>
                    <div class="acciones"><a href="checkout" class="modificarCesta">Confirmar compra</a></div>
                    <% }
                                       }%>
                    <div class="clear"></div>
                </div>
                
                <div class="clear"></div>
            </div>
            
           <%@include file= "pie.jsp" %>
            
        </div>
    </body>
</html>
